package com.cloudbroker.bcs.platform.dav.middle.extservice.gold.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.cloudbroker.bcs.common.entity.HSBCPSBackVO;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.gold.result.GoldChangeResult;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.gold.result.GoldQryResult;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.gold.result.UserGoldJourResult;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.gold.vo.GoldChangeForm;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.gold.vo.GoldTransForm;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.gold.vo.RegisteForm;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.gold.vo.UserGoldJourForm;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.gold.vo.base.GoldForm;
import com.cloudbroker.bcs.platform.dav.common.config.ConfigValues;
import com.cloudbroker.bcs.platform.dav.common.util.HttpsUtil;
import com.cloudbroker.bcs.platform.dav.middle.constants.HttpConstant;
import com.cloudbroker.bcs.platform.dav.middle.constants.IFSGoldUrl;
import com.cloudbroker.bcs.platform.dav.middle.extservice.gold.GoldService;

/**
 * Created by panjx12801 on 2017/1/3.
 */
@Service
public class GoldServiceImpl implements GoldService {
    
    private static final Logger logger = LoggerFactory.getLogger(GoldServiceImpl.class);
    
    private String getUrl(String request_url) {
        String url = ConfigValues.getGoldIntUrl();
        url = url + request_url;
        return url;
    }
    
    @Override
    public HSBCPSBackVO goldRegiste(RegisteForm param) {
        Map<String, Object> params = HttpsUtil.beanToMap(param);
        String result = HttpsUtil.doGet(getUrl(IFSGoldUrl.GOLD_REGISTE), params, HttpConstant.CHARSET_UTF_8, "");
        return JSONObject.parseObject(result, HSBCPSBackVO.class);
    }
    
    @Override
    public GoldChangeResult goldChange(GoldChangeForm param) {
        Map<String, Object> params = HttpsUtil.beanToMap(param);
        String result = HttpsUtil.doGet(getUrl(IFSGoldUrl.GOLD_CHANGE), params, HttpConstant.CHARSET_UTF_8, "");
        return JSONObject.parseObject(result, GoldChangeResult.class);
    }
    
    @Override
    public GoldChangeResult goldTrans(GoldTransForm param) {
        Map<String, Object> params = HttpsUtil.beanToMap(param);
        String result = HttpsUtil.doGet(getUrl(IFSGoldUrl.GOLD_TRANS), params, HttpConstant.CHARSET_UTF_8, "");
        return JSONObject.parseObject(result, GoldChangeResult.class);
    }
    
    @Override
    public GoldQryResult userCurGoldQry(GoldForm param) {
        Map<String, Object> params = HttpsUtil.beanToMap(param);
        String result = HttpsUtil.doGet(getUrl(IFSGoldUrl.GOLD_QRY), params, HttpConstant.CHARSET_UTF_8, "");
        return JSONObject.parseObject(result, GoldQryResult.class);
    }
    
    @Override
    public UserGoldJourResult getUserGoldJour(UserGoldJourForm param) {
        Map<String, Object> params = HttpsUtil.beanToMap(param);
        String result = HttpsUtil.doGet(getUrl(IFSGoldUrl.GOLD_JOUR), params, HttpConstant.CHARSET_UTF_8, "");
        return JSONObject.parseObject(result, UserGoldJourResult.class);
    }
    
}
